﻿@using System.Data
@using ZoomLa.BLL
@using ZoomLa.BLL.Content
@using ZoomLa.BLL.Helper
@using ZoomLa.Common
@using ZoomLa.SQLDAL
@using ZoomLaCMS.Models.Field
@model ZoomLaCMS.Models.Content.VM_ContentManage
@functions{
    B_Content bll = new B_Content();
    Dictionary<int, DataTable> fieldDic = new Dictionary<int, DataTable>();
    MvcHtmlString NullHtml = MvcHtmlString.Create("");
    string adminPath = CustomerPageAction.customPath2 + "Content/";
    //显示模型标识图片
    public MvcHtmlString GetPic(object modelid)
    {
        int mid = DataConverter.CLng(modelid);
        if (Model.ModelDT == null || Model.ModelDT.Rows.Count < 1 || mid < 1) { return NullHtml; }
        DataRow[] drs = Model.ModelDT.Select("ModelID=" + modelid);
        if (drs.Length < 1) { return MvcHtmlString.Create(""); }
        else
        {
            drs[0]["ItemName"] = DataConverter.CStr(drs[0]["ItemName"]);
            if (drs[0] == null || string.IsNullOrEmpty(DataConverter.CStr(drs[0]["ItemIcon"]))) { return NullHtml; }
            return MvcHtmlString.Create("<span class=\"" + drs[0]["ItemIcon"] + "\" />");
        }
    }
    //显示标题
    public MvcHtmlString GetTitle(DataRow dr)
    {
        int gid = DataConverter.CLng(dr["GeneralID"]);
        int nodeid = DataConverter.CLng(dr["NodeID"]);
        string title = StringHelper.SubStr(dr["Title"]);
        string style = DataConverter.CStr(dr["TitleStyle"]);
        string n = "";
        if (nodeid == Model.NodeID)
        {
            n = "<a style=\"" + style + "\" href=\""+adminPath+"ShowContent.aspx?GID=" + gid + "\">" + title + "</a>";
        }
        else
        {
            n = "<strong>[<a href=\"ContentManage?NodeID=" + nodeid + "\">" + dr["NodeName"] + "</a>]</strong><a style=\"" + style + "\" href=\""+adminPath+"ShowContent.aspx?GID=" + gid + "\">" + title + "</a>";
        }
        return MvcHtmlString.Create(n);
    }
    public MvcHtmlString GetShowField(DataRow dr)
    {
        int modelID = DataConverter.CLng(dr["ModelID"]);
        string tbname = DataConverter.CStr(dr["TableName"]);
        //避免重复取多次数
        if (!fieldDic.ContainsKey(modelID))
        {
            fieldDic[modelID] = DBCenter.Sel("ZL_ModelField", "ModelID=" + modelID + " AND IsChain=1","OrderID ASC");
        }
        DataTable fieldDT = fieldDic[modelID];
        DataTable valueDT = bll.GetContentByItems(tbname, DataConverter.CLng(dr["GeneralID"]));
        if (fieldDT.Rows.Count < 1 || valueDT.Rows.Count < 1) { return NullHtml; }
        VM_FieldModel field = new VM_FieldModel();
        field.fieldDT = fieldDT;
        field.valueDR = valueDT.Rows[0];
        return Html.Partial("Fields/Index_Admin_ContentManage",field);
    }
}
@{
    Model.setting.cols = 9;
    //Model.setting.page_mode = "dp";
    Model.setting.url = "ContentManage";
    string siteUrl = ZoomLa.Components.SiteConfig.SiteInfo.SiteUrl;
    ContentHelper conHelper = new ContentHelper();
}
<table id="EGV" class="table table-striped table-bordered table-hover content_list">
	<tr>
		<td></td><td>ID</td><td>标题</td>
		<td class="egv_td_min60">录入者</td><td>点击数</td><td>推荐</td><td class="egv_td_min60">状态</td><td>排序</td><td>操作</td>
	</tr>
    @foreach (DataRow dr in Model.setting.dt.Rows)
    {
        <tr ondblclick="location='@(adminPath)ShowContent.aspx?GID=@dr["GeneralID"]';" data-order="@dr["OrderID"]" data-gid="@dr["GeneralID"]">
            <td class="td_s"> <input type="checkbox" name="idchk" value='@dr["GeneralID"]' /></td>
            <td class="GID">@dr["GeneralID"]</td>
            <td>
                <div class="Ctitle" onmouseover="ShowPopover(this)" onmouseout="HidePopover(this)">
                    <span class="hidden-xs">@GetPic(dr["ModelID"])@GetTitle(dr)</span>
                    <div class="popover bottom">
                        <div class="arrow"></div>
                        <h3 class="popover-title">
                            <a href="/Item/@(dr["GeneralID"]).aspx" target="_blank">@dr["Title"]</a><span class="badge pull-right">@dr["Hits"]</span>
                                <span class="gray_9">[@DateHelper.ToDate(dr["CreateTime"])]</span>
                        </h3>
                        <div class="popover-content">
                            @GetShowField(dr)
                            <div class="clearfix"></div>
                        </div>
                    
                    </div>
                </div>
            </td>
            <td><a href="ContentManage?NodeID=@dr["NodeID"]&KeyType=1&keyWord=@(HttpUtility.UrlEncode(DataConverter.CStr(dr["Inputer"])))">@dr["Inputer"]</a></td>
            <td>@dr["Hits"]</td>
            <td>@MvcHtmlString.Create(conHelper.GetElite(DataConverter.CStr(dr["EliteLevel"])))</td>
            <td>
                @conHelper.GetStatus(DataConverter.CLng(dr["Status"]))
            </td>
            <td>
                <a class="option_style" href="javascript:;" onclick="MoveItem(this,'up')">↑上移 </a>
                <a class="option_style" href="javascript:;" onclick="MoveItem(this,'down')">下移↓</a>
            <td style="position:relative;">
                <div class="popover left" style="width:180px;left:-180px;top:-75px;">
                    <div class="arrow"></div>
                    <div class="popover-content" style="width:180px;">
                        <img src="/common/common.ashx?url=@(siteUrl+"/Item/"+dr["GeneralID"]+".aspx")" style="width:150px;height:150px;" />
                    </div>
                </div>
                <a class="precode" href="javascript:;" @(dr["Status"].ToString().Equals("99")?"":"hidden") data-gid='@dr["GeneralID"]'><i class="fa fa-qrcode"></i></a>
                @*<a class="option_style" href="/design/h5/?id=@dr["GeneralID"]" title="H5与移动创作" target="_blank"><i class="fa fa-magic"></i></a>*@
                <a class="option_style" href="@(adminPath)ShowContent.aspx?GID=@dr["GeneralID"]"  title="预览" ><i class="fa fa-eye"></i></a>
                <a class="option_style" href="EditContent?GeneralID=@dr["GeneralID"]"><i class="fa fa-pencil" title="修改"></i></a>
                <a class="option_style" href="javascript:;" onclick="mvcpage.del({ url: 'ContentManage_Del', ids: '@dr["GeneralID"]',confirm:'你确定将该数据删除到回收站吗'});"><i class="fa fa-trash" title="删除"></i></a>
                <a class="option_style" href="/Item/@(dr["GeneralID"]).aspx" target="_blank"><i class='fa fa-globe'> </i>浏览</a>
                @if (DataConvert.CLng(dr["IsCreate"])==0)
                {
                    <a class="option_style" href="javascript:;" onclick="mvcpage.post({ url: 'ContentManage_Html', data: {id:'@dr["GeneralID"]',action:'create'},callback:'reload'});"><i class="fa fa-play"></i>生成HTML</a>
                }
                else
                {
                    <a class="option_style" href="javascript:;" onclick="mvcpage.post({ url: 'ContentManage_Html', data: {id:'@dr["GeneralID"]',action:'del'},callback:'reload'});"><i class="fa fa-play"></i>删除HTML</a>
                }
                <a class="option_style" href="javascript:;" onclick="mvcpage.del({ url: 'ContentManage_Refresh', ids: '@dr["GeneralID"]'});"><i class="fa fa-refresh" title="刷新"></i>刷新</a>
                </td>
            </tr>
    }
@Html.Partial("_page",Model.setting)
</table>
